package com.wyg.epkafkastarter.config;

import com.wyg.epkafkastarter.producer.BaseProducer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.*;
import org.springframework.kafka.core.*;

/**
 * @Author: WangYongGan
 * @Date: 2022/5/17 18:34
 * @Description:
 */
@Configuration
@EnableConfigurationProperties(KafkaConfigProperties.class)
public class AutoConfig {
    public AutoConfig(KafkaConfigProperties kafkaConfigProperties) {

    }


    @Bean
    @Conditional(ProducerCondition.class)
    public KafkaTemplate<String, String> kafkaTemplate(KafkaConfigProperties kafkaConfigProperties) {
        if (kafkaConfigProperties.getType_() != 0) {
            BaseProducer.kafkaTemplate = new KafkaTemplate<>(ProducerConfig.producerFactory());
            return BaseProducer.kafkaTemplate;
        }
        return null;
    }

}
